package com.bw.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bw.service.TmsService;
import org.apache.tomcat.Jar;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author Lenovo
 * @date 2025年09月02日 10:33
 */
@RestController
public class TmsController {
    @Autowired
    private TmsService tmsService;

    @RequestMapping("/s1")
    public JSONObject select1(){
        JSONObject result = new JSONObject();
        result.put("status",0);
        result.put("msg","");
        JSONObject data = new JSONObject();
        result.put("data",data);
        List<Map<String,Object>>maps=tmsService.select1();
        Map<String, Object> map = maps.get(0);
        result.put("data",map.get("cta"));
        return result;
    }

    @RequestMapping("/s2")
    public JSONObject select2(){
        JSONObject result = new JSONObject();
        result.put("status",0);
        result.put("msg","");
        JSONArray data = new JSONArray();
        result.put("data",data);

        List<Map<String,Object>>maps=tmsService.select2();
        for (Map<String, Object> map : maps) {
            JSONObject row = new JSONObject();
            row.put("name",map.get("name"));
            row.put("value",map.get("cta"));
            data.add(row);

        }
        return result;
    }

    @RequestMapping("/s3")
    public  JSONObject select3(){
        JSONObject retult = new JSONObject();
        retult.put("status",0);
        retult.put("msg","");
        JSONObject data = new JSONObject();
        retult.put("data",data);

        JSONArray columns = new JSONArray();
        JSONArray rows = new JSONArray();
        data.put("columns",columns);
        data.put("rows",rows);

        JSONObject col1 = new JSONObject();
        col1.put("id","name");
        col1.put("name","机构的名称");

        JSONObject col2 = new JSONObject();
        col2.put("id","cta");
        col2.put("name","完成运输次数");

        JSONObject col3 = new JSONObject();
        col3.put("id","ctb");
        col3.put("name","排名");

        columns.add(col1);
        columns.add(col2);
        columns.add(col3);

        List<Map<String,Object>>maps=tmsService.select3();
        for (Map<String, Object> map : maps) {
            JSONObject row = new JSONObject();
            row.put("name",map.get("name"));
            row.put("cta",map.get("cta"));
            row.put("ctb",map.get("ctb"));
            rows.add(row);
        }
        return retult;
    }

    @RequestMapping("/s4")
    public  JSONObject select4(){
        JSONObject retult = new JSONObject();
        retult.put("status",0);
        retult.put("msg","");
        JSONObject data = new JSONObject();
        retult.put("data",data);

        JSONArray mapData = new JSONArray();

        data.put("mapData",mapData);

        List<Map<String,Object>>maps=tmsService.select4();
        for (Map<String, Object> map : maps) {
            JSONObject row = new JSONObject();
            row.put("name",map.get("name"));
            row.put("value",map.get("cta"));
            row.put("sizevalue",map.get("ctb"));
            mapData.add(row);
        }
        return retult;
    }
}
